from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-17 14:13:14.764959
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 17, Sep, 2021
Time: 14:13:19
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2139
Nobs: 417.000 HQIC: -46.7402
Log likelihood: 4581.81 FPE: 3.56089e-21
AIC: -47.0844 Det(Omega_mle): 2.87695e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437329 0.092822 4.711 0.000
L1.Burgenland 0.104969 0.047935 2.190 0.029
L1.Kärnten -0.114521 0.023916 -4.788 0.000
L1.Niederösterreich 0.162709 0.102653 1.585 0.113
L1.Oberösterreich 0.118610 0.100877 1.176 0.240
L1.Salzburg 0.284335 0.050319 5.651 0.000
L1.Steiermark 0.025739 0.066747 0.386 0.700
L1.Tirol 0.109369 0.052749 2.073 0.038
L1.Vorarlberg -0.108492 0.047370 -2.290 0.022
L1.Wien -0.013040 0.091743 -0.142 0.887
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012286 0.214117 0.057 0.954
L1.Burgenland -0.048434 0.110573 -0.438 0.661
L1.Kärnten 0.036831 0.055168 0.668 0.504
L1.Niederösterreich -0.216573 0.236795 -0.915 0.360
L1.Oberösterreich 0.481949 0.232697 2.071 0.038
L1.Salzburg 0.306860 0.116072 2.644 0.008
L1.Steiermark 0.117492 0.153968 0.763 0.445
L1.Tirol 0.315051 0.121678 2.589 0.010
L1.Vorarlberg 0.003197 0.109270 0.029 0.977
L1.Wien 0.003027 0.211628 0.014 0.989
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.247477 0.047238 5.239 0.000
L1.Burgenland 0.090225 0.024394 3.699 0.000
L1.Kärnten -0.001506 0.012171 -0.124 0.902
L1.Niederösterreich 0.209451 0.052241 4.009 0.000
L1.Oberösterreich 0.170054 0.051337 3.313 0.001
L1.Salzburg 0.033749 0.025607 1.318 0.188
L1.Steiermark 0.018446 0.033968 0.543 0.587
L1.Tirol 0.065808 0.026844 2.451 0.014
L1.Vorarlberg 0.059142 0.024107 2.453 0.014
L1.Wien 0.108887 0.046689 2.332 0.020
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181340 0.046130 3.931 0.000
L1.Burgenland 0.049265 0.023822 2.068 0.039
L1.Kärnten -0.006527 0.011886 -0.549 0.583
L1.Niederösterreich 0.137699 0.051016 2.699 0.007
L1.Oberösterreich 0.316753 0.050133 6.318 0.000
L1.Salzburg 0.100854 0.025007 4.033 0.000
L1.Steiermark 0.132305 0.033171 3.989 0.000
L1.Tirol 0.075094 0.026215 2.865 0.004
L1.Vorarlberg 0.057110 0.023541 2.426 0.015
L1.Wien -0.044178 0.045594 -0.969 0.333
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207682 0.091672 2.265 0.023
L1.Burgenland -0.051131 0.047341 -1.080 0.280
L1.Kärnten -0.034786 0.023620 -1.473 0.141
L1.Niederösterreich 0.107323 0.101381 1.059 0.290
L1.Oberösterreich 0.171888 0.099626 1.725 0.084
L1.Salzburg 0.253614 0.049695 5.103 0.000
L1.Steiermark 0.080771 0.065920 1.225 0.220
L1.Tirol 0.123838 0.052095 2.377 0.017
L1.Vorarlberg 0.115533 0.046783 2.470 0.014
L1.Wien 0.029440 0.090606 0.325 0.745
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.029703 0.070957 0.419 0.676
L1.Burgenland 0.023851 0.036643 0.651 0.515
L1.Kärnten 0.052304 0.018282 2.861 0.004
L1.Niederösterreich 0.212375 0.078472 2.706 0.007
L1.Oberösterreich 0.334183 0.077114 4.334 0.000
L1.Salzburg 0.045425 0.038465 1.181 0.238
L1.Steiermark -0.005602 0.051024 -0.110 0.913
L1.Tirol 0.113827 0.040323 2.823 0.005
L1.Vorarlberg 0.066405 0.036211 1.834 0.067
L1.Wien 0.128390 0.070132 1.831 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186628 0.086984 2.146 0.032
L1.Burgenland 0.017156 0.044920 0.382 0.703
L1.Kärnten -0.057710 0.022412 -2.575 0.010
L1.Niederösterreich -0.108455 0.096197 -1.127 0.260
L1.Oberösterreich 0.186753 0.094532 1.976 0.048
L1.Salzburg 0.031388 0.047154 0.666 0.506
L1.Steiermark 0.300170 0.062549 4.799 0.000
L1.Tirol 0.486728 0.049431 9.847 0.000
L1.Vorarlberg 0.068968 0.044390 1.554 0.120
L1.Wien -0.108917 0.085973 -1.267 0.205
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161475 0.094560 1.708 0.088
L1.Burgenland -0.010365 0.048832 -0.212 0.832
L1.Kärnten 0.061640 0.024364 2.530 0.011
L1.Niederösterreich 0.190668 0.104575 1.823 0.068
L1.Oberösterreich -0.129901 0.102765 -1.264 0.206
L1.Salzburg 0.237498 0.051261 4.633 0.000
L1.Steiermark 0.158556 0.067997 2.332 0.020
L1.Tirol 0.052303 0.053736 0.973 0.330
L1.Vorarlberg 0.125831 0.048257 2.608 0.009
L1.Wien 0.155112 0.093461 1.660 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487071 0.051310 9.493 0.000
L1.Burgenland -0.008589 0.026497 -0.324 0.746
L1.Kärnten -0.010119 0.013220 -0.765 0.444
L1.Niederösterreich 0.203660 0.056745 3.589 0.000
L1.Oberösterreich 0.261785 0.055763 4.695 0.000
L1.Salzburg 0.021055 0.027815 0.757 0.449
L1.Steiermark -0.024544 0.036896 -0.665 0.506
L1.Tirol 0.067930 0.029158 2.330 0.020
L1.Vorarlberg 0.058899 0.026185 2.249 0.024
L1.Wien -0.054052 0.050714 -1.066 0.287
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021522 0.076059 0.139834 0.132840 0.041204 0.075003 -0.002733 0.177552
Kärnten 0.021522 1.000000 -0.044317 0.126649 0.047108 0.069162 0.454587 -0.093556 0.092221
Niederösterreich 0.076059 -0.044317 1.000000 0.283489 0.081316 0.265919 0.023241 0.136280 0.257891
Oberösterreich 0.139834 0.126649 0.283489 1.000000 0.181037 0.284963 0.156289 0.099032 0.137944
Salzburg 0.132840 0.047108 0.081316 0.181037 1.000000 0.126050 0.054860 0.101655 0.050811
Steiermark 0.041204 0.069162 0.265919 0.284963 0.126050 1.000000 0.130531 0.088825 -0.023854
Tirol 0.075003 0.454587 0.023241 0.156289 0.054860 0.130531 1.000000 0.039752 0.115509
Vorarlberg -0.002733 -0.093556 0.136280 0.099032 0.101655 0.088825 0.039752 1.000000 -0.049572
Wien 0.177552 0.092221 0.257891 0.137944 0.050811 -0.023854 0.115509 -0.049572 1.000000